#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N];
int n;
bool f[N];
int add(int i,bool v){
    int num=0;
    f[i]=v;
    for(int j=i-2;j>=0;j--){
        if(f[j]==v&&a[j]==a[i]){
            num=a[i];
            break;
        }
    }
    if(i==n)return num;
    return max(add(i+1,false),add(i+1,true))+num;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        cin>>n;
        for(int j=0;j<n;j++)cin>>a[i];
        cout<<max(add(1,false),add(1,true))<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
/*AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKI*/